<?php namespace Admin\Controller;

class LinkController extends CommonController
{
	protected $db;
	public function __init()
	{
		$this->db = new \Common\Model\Link;
	}
	/*首页*/
	public function index()
	{
		/*获取所有数据*/
		$oldData = $this->db->get();
		/*分配变量*/
		View::with("oldData",$oldData);
		View::make();
	}
	/*添加*/
	public function addLink()
	{
		
		if(IS_POST)
		{			
			if(!$this->db->addLink())
			{
				/*如果添加失败*/
				View::error($this->db->getError());
			}else{
				//如果添加成功
				$this->success("添加成功",U('index'));
			}
		}
		
		
		
		View::make();
	}
	/*编辑*/
	public function edit()
	{
		
		if(IS_POST)
		{			
			if(!$this->db->edit())
			{
				/*如果添加失败*/
				View::error($this->db->getError());
			}else{
				//如果添加成功
				$this->success("编辑成功",U('index'));
			}
		}
		
		//获取旧数据
		$lid = Q("get.lid",0,'intval');
		$oldData = $this->db->where("lid",$lid)->first();
		/*分离变量*/
		View::with("oldData",$oldData);

		
		View::make();
	}
	//删除
	public function del()
	{
		$lid = Q('get.lid',0,'intval');
		$this->db->where('lid',$lid)->delete();
		$this->success("删除成功",U('index'));
	}
	
}



























